package com.vshop.framework.web.autoconfig;

import com.vshop.framework.core.constant.WebFilterOrderConst;
import com.vshop.framework.web.trace.WebTraceFilter;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

@Slf4j
@AutoConfiguration
@ConditionalOnWebApplication
public class WebTraceAutoConfig {
    @PostConstruct
    public void postConstruct() {
        log.info("初始化 WebTraceAutoConfig");
    }

    @Bean
    public FilterRegistrationBean<WebTraceFilter> webTraceFilter() {
        FilterRegistrationBean<WebTraceFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new WebTraceFilter());
        registrationBean.addUrlPatterns("/*"); // 设置过滤的URL模式
        registrationBean.setName("webTraceFilter");
        registrationBean.setOrder(WebFilterOrderConst.TraceFilter);
        return registrationBean;
    }
}
